<template>
  <!--预约类订单详情页面-->
  <div class="yuyue">
    <wv-panel>
      <wv-media-box :thumb="orderDetail.coverImg | imgPathFilter" :title="orderDetail.goodsName"
                    :description="'×1'"></wv-media-box>
    </wv-panel>
    <div class="divider"></div>
    <ul class="address">
      <li><img src="../../assets/clock.png" alt="" width="15">{{orderDetail.time}}</li>
      <li><span><img src="../../assets/address.png" alt="" width="15"></span>
        <span>{{orderDetail.address}}</span>
      </li>
      <li><img src="../../assets/clock.png" alt="" width="15">有效期至：{{orderDetail.expireDate}}</li>
    </ul>
    <div class="divider"></div>
    <div class="list" v-show="order.orderStatus!=1">
      <ul>
        <span style="color: #f92014" v-if="orderDetail.goodState==1"> 已过期</span>
        <span style="color: #2c9bed" v-if="orderDetail.goodState==2"> 已使用</span>
        <li>
          <div id="qrCode" style="width: 100px;height: 100px"></div>
        </li>
        <li>{{agentCodeStr}}</li>
      </ul>
      <p v-if="orderDetail.goodState!=1&&orderDetail.goodState!=2">
        <wv-button type="primary" :plain="true" @click="turnSubmitInfo()" style="margin-bottom: 10px">填写使用人资料
        </wv-button>
      </p>
    </div>
    <div class="divider" v-show="order.orderStatus!=1"></div>
    <ul class="msg">
      <li>使用说明</li>
      <li>1.使用贵宾厅时，您可将核验二维码出示给机场工作人员即可；</li>
      <li>2.转赠他人使用贵宾厅时，您可点击上方“发送短信”按钮，添加接收人手机号码可将贵宾厅核验二维码发送；</li>
    </ul>
    <div class="divider"></div>
    <ul class="msg">
      <li>订单编号：{{order.orderNo}}</li>
      <li v-if="order.orderStatus==1">订单状态：待付款</li>
      <li v-if="order.orderStatus==2">订单状态：已付款</li>
      <li v-if="order.orderStatus==3">订单状态：已退款</li>
      <li>订单时间：{{order.createDate}}</li>
      <li>支付时间：{{order.payDate}}</li>
      <li v-if="order.payType=='PAY_WX'">支付方式：微信</li>
      <li v-if="order.payType=='PAY_ALI'">支付方式：支付宝</li>
      <li v-if="order.payType=='PAY_UNDERLINE'">支付方式：线下</li>
      <li>支付金额：{{order.totalPrice}}元</li>
    </ul>
    <p class="offer" @click="goIndex()">返回</p>
  </div>
</template>

<script type="text/ecmascript-6">
  import {getOrderDetail, getAccountGoodsInfo} from '../../utils/http'
  import QRCode from 'qrcodejs2'
  import {Toast} from 'we-vue'

  export default {
    name: 'orderdetailnoyuyue',
    props: {},
    data() {
      return {
        isVisible: false,
        order: {},
        orderDetail: {},
        accountGoodsQrCode: '',
        accountGoodsId: ''
      };
    },
    methods: {
      generateQrCode(text) {
        new QRCode('qrCode', {
          width: 100,
          height: 100,        // 高度
          text: text,   // 二维码内容
          render: 'canvas',   // 设置渲染方式（有两种方式 table和canvas，默认是canvas）
          background: '#f0f',   // 背景色
          foreground: '#ff0'    // 前景色
        })
      },
      getOrderDetailData(params) {
        getOrderDetail(params).then(res => {
          console.log(res);
          if (res.code == 100) {
            this.order = res.object.order;
            let orderDetailList = res.object.orderDetailList;
            let length = orderDetailList.length;
            let accountGoodsQrCode = res.object.accountGoodsQrCode;
            let accountGoodsId = res.object.accountGoodsId;
            this.accountGoodsQrCode = accountGoodsQrCode;
            this.accountGoodsId = accountGoodsId;
            if (length == 1) {
              this.orderDetail = orderDetailList[0];
            }
            this.generateQrCode(this.accountGoodsQrCode);
          }
        })
      },
      turnSubmitInfo() {
        getAccountGoodsInfo({accountGoodsId: this.accountGoodsId}).then(res => {
          if (res.code == 100) {
            let goodState = res.object.goodState;
            this.orderDetail.goodState = goodState
            if (goodState == 1) {
              Toast.fail('物品已过期')
              return
            }
            if (goodState == 2) {
              Toast.fail('物品已使用')
              return
            }
            this.$router.push({path: 'subuseinfo', query: {accountGoodsId: this.accountGoodsId}})
          }
        })

      },
      goIndex() {
        this.$router.push({path: 'index'})
      }
    },
    created() {
      let orderId = this.$route.query.orderId;
      this.getOrderDetailData({orderId: orderId});
    },
    computed: {
      agentCodeStr: function () {
        return this.$myUtils.replaceStr(this.accountGoodsQrCode)
      }
    }
  }
</script>

<!-- Add "scoped" attribute to limit CSS to this component only -->
<style scoped lang="less" rel="stylesheet/less">
  .divider {
    background-color: #eee;
    height: 10px;
  }

  .msg {
    padding: 10px;
    font-size: 13px;
    color: #666;
    line-height: 25px;
    text-align: left;
  }

  .address {
    background-color: #fff;
    padding: 10px;
    text-align: left;

    li {
      height: 40px;
      line-height: 40px;
      border-bottom: 1px solid #eee;

      img {
        margin-right: 5px;
        vertical-align: text-bottom;

      }
    }

    li:nth-child(2) {
      display: flex;
      padding: 10px 0;
      height: auto;
      align-items: center;

      span:first-child {
        flex: 0 20px;

        img {
          vertical-align: top;
          padding-top: 5px;
        }
      }

      span:last-child {
        line-height: 22px;
      }
    }

    li:last-child {
      height: 40px;
      line-height: 40px;
      border-bottom: 1px solid #eee;

      img {
        margin-right: 5px;
        vertical-align: text-bottom;

      }
    }
  }

  .des {
    font-size: 18px;
    color: #111;
    text-align: left;
    padding: 10px;
  }

  .deslist {
    font-size: 13px;
    color: #666;
    text-align: left;
    padding: 0 10px 10px;
    line-height: 25px;
  }

  .title {
    font-size: 18px;
    color: #111;
    padding: 10px 10px 0;
    text-align: left;
  }

  .yuyue {
    padding-bottom: 50px;
  }

  .other {
    padding: 20px 0;

    p {
      color: #111;
    }

    .content p {
      padding-top: 20px;
    }
  }

  .shouqi {
    margin-top: 10px;
  }

  .list {
    width: 80%;
    margin: auto;
    background-size: 100% 100%;

    ul {
      color: #111;
      font-size: 13px;
      padding: 30px;
      text-align: center;

      li {
        div {
          margin: 0 auto;
          border: 1px solid #f6fffc;
        }
      }

      li:last-child {
        margin-top: 5px;
        font-size: 18px;
      }
    }

  }

  .offer {
    position: fixed;
    bottom: 0;
    width: 100%;
    background-image: linear-gradient(to left, #4c92ed, #61beec);
    height: 50px;
    line-height: 50px;
    color: #fff;
    z-index: 999;
  }
</style>
